package com.yunang.officialweb.controller;

import com.yunang.officialweb.common.R;
import com.yunang.officialweb.entity.Footer;
import com.yunang.officialweb.service.FooterService;
import com.yunang.officialweb.service.TotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/OfficialWebsite")
public class FooterController {

    @Autowired
    private FooterService footerService;

    @Autowired
    private TotalService totalService;

    @RequestMapping(value = "/selectFooter", method = RequestMethod.GET)
    public R selectFooter() {

        return R.ok(footerService.selectFooter());
    }

    @RequestMapping(value = "/updateFooter", method = RequestMethod.PUT)
    public R updateFooter(
            @RequestParam String qq,
            @RequestParam String weixin,
            @RequestParam String email,
            @RequestParam String officialAccount,
            @RequestParam MultipartFile file) {
        Footer footer = new Footer();
        footer.setQq(qq);
        footer.setWeixin(weixin);
        footer.setEmail(email);
        footer.setOfficialAccount(officialAccount);
        footer.setImage(totalService.savePic(file, "D://YunAng-web//footer"));
        return R.ok(footerService.updateFooter(footer));
    }

}
